<?php
/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */


/**
 * WBLabel 
 *
 * @package php.ui.winbinder
 */ 
class WBLabel extends WBControl { 
	public function __construct($options = array()) { 
		$options['class'] = Label;

		parent::__construct($options);
	}
	
	public function initCreate() { 
		parent::initCreate();
		
		$style = $this['style'];

		if (isset($this->align))		$style |= wbconstant($this->getOption('align'));

		$this['style'] = $style;
		
	}

	// 객체 초기화 
	protected function initComponent() { 
		parent::initComponent();


		if (isset($this->border))		$this->setBorder($this->getOption('border'));
		if (isset($this->ellipsis))		$this->setEllipsis($this->getOption('ellipsis'));
		if (isset($this->multiline))	$this->setMultiLine($this->getOption('multiline'));


	}

	/**
	 * text align 설정 
	 * 
	 * @param string|int $direction 위치 지정, WBC_LEFT or 'left', 'right', 'center'
	 */
	public function setAlign($direction = WBC_LEFT) { 
		if (is_string($direction)) { 
			if(in_list($direction, 'left', 'right', 'center')) { 
				$direction = wbconstant($direction);
			}
		}

		$this->setStyle($direction, true);
	}

	/**
	 * text 수평 align 설정 
	 * 
	 * @param string|int $direction 위치 지정, WBC_LEFT or 'left', 'right', 'center'
	 */	
	public function setValign($direction = WBC_TOP) { 
		$this->setStyle(wbconstant($direction), true);
	}

	/**
	 * Label 에 border 설정하기 
	 * 
	 * @see WBControl#setBorder($isBorder)
	 */
	public function setBorder($isBorder = true) { 
		$this->setStyle(WBC_BORDER, $isBorder);
	}

	/**
	 * XXX
	 * 
	 * @param bool $isEllipsis
	 */
	public function setEllipsis($isEllipsis = true) { 
		$this->setStyle(WBC_ELLIPSIS, $isEllipsis);
	}

	/**
	 * 여러줄 사용 가능 
	 * 
	 * @param bool $isEllipsis
	 */	
	public function setMultiLine($isMultiLine = true) { 
		$this->setStyle(WBC_MULTILINE, $isMultiLine);
	}

	/**
	 * 생성된 기본 크기 얻어오기 
	 * 
	 * @see WBComponent#getPreferedSize()
	 */
	public function getPreferedSize() { 
		$arr = wb_get_size($this->getText());

		return array(
			'width' => $arr[0] + 14,
			'height' => $arr[1] + 10,
		);
	}
}

?>